﻿


(function ($) {

    $.fn.cQevent = function (options) {
        options = $.extend({}, $.fn.cQevent.defaultOptions, options);
        
        this.each(function () {
            var element = $(this);
            //var btnAction = (typeof options.btnAction == 'function') ? options.btnAction : function () { };
            var prefix = options.title.replace(/ /g, '').toLowerCase();

            var markup = "";
            markup += '<div class="unliq-event c-unliq-event" id="' + prefix + '-unliq-event">'
            markup += '<div class="title" parent="' + prefix + '"><div class="float-left" style="width: 89%;">' + options.title + '</div><div parent="' + prefix + '" id="' + prefix + '-close-btn" class="float-left fui-cross-16 close-btn" style="cursor:pointer"></div></div>'
            markup += '<div class="desc">'
            markup += '<ul style="color:#2c3e50">'
            markup += '<li><div class="float-left">Person in charge:</div><div class="float-left" style="font-weight:bold">'+ options.personincharge +'</div></li>'
            markup += '<li><div class="float-left">Room:</div><div class="float-left" style="font-weight:bold">'+ options.room +'</div></li>'
            markup += '</ul>'
            markup += '</div>'
            markup += '<div class="nums">'
            markup += '<div class="onq">'
            markup += '<div class="onq-title">On Q</div>'
            markup += '<div class="onq-num" id="c-' + prefix + 'onq-num">15</div>'
            markup += '</div>'
            markup += '<div class="nowserving">'
            markup += '<div class="nowserving-title">Now Serving</div>'
            markup += '<div class="nowserving-num" id="c-' + prefix + 'nowserving-num">05</div>'
            markup += '</div>'
            markup += '<div style="clear:both"></div>'
            markup += '</div>'
            markup += '<div class="event-btns">'
            markup += '<input type="button" class="btn btn-info  event-btn" id="' + prefix + 'btn-nxt" value="Next" eventname="' + prefix + '"/>'
            markup += '<div style="clear:both"></div>'
            markup += '</div>'
            markup += '</div>'
            
            element.html(markup);

            $('#' + prefix + 'btn-nxt').click(function () {
                var str = $('#c-' + prefix + 'nowserving-num').html();
                    if (str.substring(0, 1) == '0') {
                        str = str.substring(1);
                    }


                    var nxtQ = parseInt(str) + 1;
                    var strQ = nxtQ.toString();
                    if (nxtQ.toString().length == 1) {
                        strQ = "0" + nxtQ;
                    }

                    if (strQ.length > 2) {
                        $('#c-' + prefix + 'nowserving-num').css("font-size", '72px');
                    }
                    $('#c-' + prefix + 'nowserving-num').html(strQ);

                    var str = $('#c-' + prefix + 'nowserving-num').html();
                    var str = $('#c-' + prefix + 'nowserving-num').html();
                    if ($('c-' + prefix + 'onq-num').html.toString() != str) { 
                        
                    }
            });

            $('#'+ prefix + '-close-btn').click(function () {
                $('#' + prefix + '-unliq-event').remove();
                if (typeof options.closeFn != 'undefined') {
                    options.closeFn();
                }
            })
        });

        return this;
    }
})(jQuery);